<template>
  <view class="search">
    <view class="container">
      <view class="search-wrapper">
        <view class="search-input">
          <view class="search-input-wrapper">
            <view class="left">
              <text class="search-icon iconfont icon-search"></text>
            </view>
            <view class="right">
              <input
                v-model="searchValue"
                class="input"
                :focus="true"
                placeholder="请输入您搜索的商品"
                type="text"
              />
            </view>
          </view>
        </view>
        <view class="search-button">
          <view class="button" @click="onSearch">搜索</view>
        </view>
      </view>
    </view>
    <scroll-view enable-back-to-top scroll-y class="scroll-view" @scrolltolower="onScrolltolower">
      <!-- 猜你喜欢 -->
      <XtxGuess ref="guessRef" />
    </scroll-view>
  </view>
</template>

<script lang="ts" setup>
import { useGuessList } from '@/hooks/useGuessList'
import { ref } from 'vue'

const searchValue = ref('')

const onSearch = () => {
  uni.showToast({
    title: '搜索接口开发中...',
    duration: 2000,
  })
}

// 猜你喜欢
const { guessRef, onScrolltolower } = useGuessList()
</script>

<style lang="scss">
page {
  background-color: #f7f7f7;
  height: 100%;
  overflow: hidden;
}

.search {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.container {
  padding: 20rpx;
  background: #f7f7f7;

  .search-wrapper {
    display: flex;
    height: 64rpx;
  }

  // 搜索输入框
  .search-input {
    width: 80%;
    background: #fff;
    border-radius: 10rpx 0 0 10rpx;
    box-sizing: border-box;
    overflow: hidden;

    .search-input-wrapper {
      display: flex;

      .left {
        display: flex;
        width: 60rpx;
        justify-content: center;
        align-items: center;

        .search-icon {
          display: block;
          color: #b4b4b4;
          font-size: 28rpx;
        }
      }

      .right {
        flex: 1;

        input {
          font-size: 28rpx;
          height: 64rpx;
          display: flex;
          align-items: center;

          .input-placeholder {
            color: #aba9a9;
          }
        }
      }
    }
  }

  // 搜索按钮
  .search-button {
    width: 20%;
    box-sizing: border-box;

    .button {
      height: 64rpx;
      font-size: 28rpx;
      border-radius: 0 10rpx 10rpx 0;
      background: #fa2209;
      color: #fff;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}

.scroll-view {
  flex: 1;
  overflow: hidden;
}
</style>
